<?
class Share_Detail extends Common{
    var $table = 'share';
    var $id_field = 'sha_id';
    var $name_field = 'sha_name';
    var $result = array();
    public function __construct($id = 0){
        parent::__construct($id);
        $this->result = db_first('SELECT sha_id,sha_title,sha_cat_id,sha_relate,sha_summary,sha_picture,sha_detail,sha_date
                                  FROM share
                                  WHERE sha_active = 1 AND sha_id = "'.$this->id.'"
                                  LIMIT 1');
        $this->name = $this->result['sha_title'];
        $this->description = $this->result['sha_summary'];
        $this->url = DOMAIN.generate_share_detail_url($this->result);
        $this->picture = DOMAIN.share_img.$this->result['sha_picture'];
    }
    public function relate() {
        $relate_id = $this->result['sha_relate'] == '' ? '0' : $this->result['sha_relate'];
        $query = new db_query('SELECT sha_id,sha_title,sha_picture FROM share WHERE sha_id IN('.$relate_id.') LIMIT 5');
        $result = $query->resultArray();unset($query);
        if(count($result) > 0) {
            return $result;
        }else {
            $query = new db_query('SELECT sha_id,sha_title,sha_picture FROM share WHERE sha_id != '.$this->result['sha_id'].' AND sha_cat_id = '.$this->result['sha_cat_id'].' LIMIT 5');
            return $query->resultArray();
        }
    }
    public function share_total_statistics($share_id) {
        $query = new db_query('SELECT sta_like,sta_view,sta_comment FROM share_statistics WHERE sta_share_id = '.$share_id.' LIMIT 1');
        $result = mysql_fetch_assoc($query->result);
        if($result) 
            return $result;
        else 
            return array('sta_like'=>0,
                         'sta_view'=>1,
                         'sta_comment'=>0);
    }
}
?>